package com.krlin.word.word.init;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author krlin
 */
@Component
public class RedisCache implements ApplicationRunner {

    @Resource
    RedisCacheService redisCacheService;

    public static final String ALL_LETTER = "ALL";

    private static final String[] LETTER_MAP = {
            "A", "B", "C", "D", "E", "F", "G",
            "H", "I", "G", "K", "L", "M", "N",
            "O", "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"
    };

    @Override
    public void run(ApplicationArguments args) throws Exception {
        redisCacheService.cacheAllWords();
        Arrays.stream(LETTER_MAP).forEach(s -> redisCacheService.cacheOneTypeWord(s));
    }
}
